package com.example.bttrace;

public class Settings{
	public static final String CHECKPOINTS[] = {"Start","CheckPoint 1","CheckPoint 2","End"};
	public static final int MINPORT = 1024;
	public static final int MAXPORT = 49151;
	public static final int DEFAULT_CHECKPOINT = 0;
	public static final int DEFAULT_PORT = 4444;
	public static final String DEFAULT_IP = "192.168.1.19";
	
	/*private int checkPoint;
	private int port;
	private String serverIP;
	
	public Settings (){
		checkPoint = DEFAULT_CHECKPOINT;
		serverIP = DEFAULT_IP;
		port = DEFAULT_PORT;
	}
	
	public Settings(int checkPoint, int port, String serverIP) {
		this.checkPoint = checkPoint;
		this.port = port;
		this.serverIP = serverIP;
	}

	public String getCheckPoint (){
		return CHECKPOINTS[checkPoint];
	}
	
	public void setCheckPoint(String point){
		checkPoint = Arrays.asList(CHECKPOINTS).indexOf(point);
	}
	
	public void setPort (int port){
		this.port = port;
	}
	
	public int getPort (){
		return port;
	}
	
	public String getServerIP (){
		return serverIP;
	}
	
	public void setServerIP (String ip){
		serverIP = ip;
	}
	*/
	
	public static boolean validPort (int port){
		return (port >= MINPORT && port <= MAXPORT);
	}
	
	public static boolean validIP (String ip) {
	    try {
	        if (ip == null || ip.isEmpty()) {
	            return false;
	        }

	        String[] parts = ip.split( "\\." );
	        if ( parts.length != 4 ) {
	            return false;
	        }

	        for ( String s : parts ) {
	            int i = Integer.parseInt( s );
	            if ( (i < 0) || (i > 255) ) {
	                return false;
	            }
	        }
	        if(ip.endsWith(".")) {
	                return false;
	        }

	        return true;
	    } catch (NumberFormatException nfe) {
	        return false;
	    }
	}
	

	/*public Settings(Parcel in){
		String[] data= new String[3];
		 
		in.readStringArray(data);
		this.checkPoint= Integer.parseInt(data[0]);
		this.port = Integer.parseInt(data[1]);
		this.serverIP = data[2];
	}
	
	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}
	 
	@Override
	public void writeToParcel(Parcel dest, int flags) {
	// TODO Auto-generated method stub
	 
		dest.writeStringArray(new String[]{String.valueOf(this.checkPoint),String.valueOf(this.port),this.serverIP});
	}
	 
	public static final Parcelable.Creator<Settings> CREATOR= new Parcelable.Creator<Settings>() { 
		@Override
		public Settings createFromParcel(Parcel source) {
			return new Settings(source);  
		}
		 
		@Override
		public Settings[] newArray(int size) {
			return new Settings[size];
		}
	};*/
}
